﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Core.Enums;

namespace Microhard.Core.Extensions
{
    public static class EnumExtension
    {
        public static string GetDisplayText(this Enum value)
        {
            Type type = value.GetType();
            var ps = type.GetFields().Where(e=>e.GetValue(value).ToString() == value.ToString());
            foreach(var p in ps)
            {
                var cusAttr = p.GetCustomAttributes(false);
                foreach(var a in cusAttr)
                {
                    var attr = a as EnumDisplayTxtAttr;
                    if(attr != null)
                    {
                        return attr.DisplayText; 
                    }
                }
            }
            return string.Empty;
        }
    }
}
